package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


/**
 * @author Morpeko
 * @description 针对表【shopping_cart(购物车)】的数据库操作Mapper
 * @createDate 2024-08-16 16:10:00
 * @Entity com.sky.pojo.ShoppingCart
 */
@Mapper
public interface ShoppingCartMapper {


    /**
     * 更新购物车中的商品数量,根据购物车ID,数量+1
     */
    @Update("UPDATE shopping_cart SET number = number + 1 where id =#{shoppingCartId}")
    void updateNumber(Long shoppingCartId);

    /**
     * 添加到购物车,把添加到购物车的商品信息插入到shopping_cart表中
     *
     * @param shoppingCart
     */
    //@Update("INSERT INTO shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) VALUES(#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount}, #{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 根据当前用户id和套餐/果蔬ID  动态查询购物车信息列表
     */
    List<ShoppingCart> selectShoppingCartList(ShoppingCart shoppingCart);

    /**
     * 根据购用户删除购物车中所有商品
     *
     * @param currentLocalUserId
     */
    @Delete("delete from shopping_cart where user_id = #{currentLocalUserId}")
    void deleteByUserId(Long currentLocalUserId);

    /**
     * 减少购物车中商品数量
     *
     * @param shoppingCart
     */
    //@Update("UPDATE shopping_cart SET number = #{number} where id =#{id}")
    void subNumber(ShoppingCart shoppingCart);

    /**
     * 根据购物车id删除购物车中的商品信息
     * @param id
     */
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteById(Long id);
    /**
     * 批量插入购物车信息
     * @param shoppingCarts
     */
    void batchInsert(List<ShoppingCart> shoppingCarts);
}




